%{
#include "Node.h"
#include "parser.tab.hpp"
#include <stdlib.h>

int line_num = 1;
%}

DIGIT	[0-9]
LETTER	[a-zA-Z]
ALPHANUMERIC {DIGIT}|{LETTER}


%%


define											{ yylval.lexeme = strdup(yytext); return DEFINE; }
return											{ yylval.lexeme = strdup(yytext); return RETURN; }
if												{ yylval.lexeme = strdup(yytext); return IF; }
else											{ yylval.lexeme = strdup(yytext); return ELSE; }
while											{ yylval.lexeme = strdup(yytext); return WHILE; }
array											{ yylval.lexeme = strdup(yytext); return ARRAY; }
"number"|"char"|"string"						{ yylval.lexeme = strdup(yytext); return TYPE; }
"print"|"time"|"resize"|"size"|"random"|"zeros"|"set_rotate"|"get_rotate"|"set_move"|"get_move"|"set_shields"|"get_shields"|"fire"|"get_energy"|"scan_distance"|"scan_angle"|"scan_id"	{
	yylval.lexeme = strdup(yytext); return COMMAND;
}
({LETTER}|_)(_|{ALPHANUMERIC})*					{ yylval.lexeme = strdup(yytext); return ID; }
"=="											{ return EQ; }
"!="											{ return NE; }
"<="											{ return LE; }
">="											{ return GE; }
"<"												{ return LS; }
">"												{ return GR; }
"&&"											{ return AND; }
"||"											{ return OR; }
{DIGIT}+										{ yylval.lexeme = strdup(yytext); return NUMBER; }
'.'												{ yylval.lexeme = strdup(yytext); return CHAR; }
\"[^"\n]*\"										{ yylval.lexeme = strdup(yytext); return STRING; }
\n												{ line_num++; }
#.*												{ ; /* Comments */ }
[ \t]											{ ; /* Whitespace */ }
"/*"(.|\n)*"*/"									{ ; /* Multiline comments */ }
.												{ // Unknown character
												  return yytext[0];
												}

